part of '../repository.dart';

const _kSuspendedLearningStageTypeValue = 'suspended';

class _SuspendedLearningStageDto extends Equatable implements _LearningStageDto {
  const _SuspendedLearningStageDto._internal({
    required this.learningEventDto,
    required this.timeDto,
    required this.repetitionNumber,
  });

  @override
  final _LearningEventDto learningEventDto;

  @override
  final _TimeDto timeDto;

  @override
  final int repetitionNumber;

  @override
  String get type => _kSuspendedLearningStageTypeValue;

  @override
  List<Object?> get props {
    return [
      learningEventDto,
      timeDto,
      repetitionNumber,
    ];
  }

  factory _SuspendedLearningStageDto.fromJson(Map<String, dynamic> json) {
    final timeJson = Map.castFrom<dynamic, dynamic, String, dynamic>(json[_kLearningStageTimeKey]);
    final timeDto = _TimeDto.fromJson(timeJson);

    final learningEventDto = _LearningEventDto.fromString(json[_kLearningStageLearningEventKey]);

    return _SuspendedLearningStageDto._internal(
      learningEventDto: learningEventDto,
      timeDto: timeDto,
      repetitionNumber: json[_kLearningStageRepetitionNumberKey],
    );
  }

  factory _SuspendedLearningStageDto.fromEntity(SuspendedLearningStage repeatableLearningStage) {
    return _SuspendedLearningStageDto._internal(
      learningEventDto: _LearningEventDto.fromEntity(repeatableLearningStage.learningEvent),
      timeDto: _TimeDto.fromEntity(repeatableLearningStage.time),
      repetitionNumber: repeatableLearningStage.repetitionNumber,
    );
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      _kLearningStageTypeKey: type,
      _kLearningStageLearningEventKey: learningEventDto.toString(),
      _kLearningStageTimeKey: timeDto.toJson(),
      _kLearningStageRepetitionNumberKey: repetitionNumber,
    };
  }

  @override
  SuspendedLearningStage toEntity() {
    return SuspendedLearningStage(
      learningEvent: learningEventDto.toEntity(),
      time: timeDto.toEntity(),
      repetitionNumber: repetitionNumber,
    );
  }
}
